package com.huabo.system.oracle.mapper;

import com.hbfk.util.PageInfo;
import com.huabo.system.oracle.entity.TblMonitorRule;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;

import java.math.BigDecimal;
import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author huabo
 * @since 2022-04-27
 */
public interface TblMonitorRuleMapper extends BaseMapper<TblMonitorRule> {

    @SelectProvider(type=TblMonitorRuleSqlConfig.class,method="findTblMonitorRuleByUser")
    List<TblMonitorRule> findTblMonitorRuleByUser(PageInfo<TblMonitorRule> pageInfo, BigDecimal staffid);

    @Select(" SELECT count(*) from TBL_MONITOR_RULE mr  \n" +
            " LEFT JOIN TBL_MONITOR_SOLUTION_RULE msr on mr.RULEID=msr.RULEID  \n" +
            " LEFT JOIN TBL_MONITOR_SOLUTION tms ON msr.SOLUTIONID = tms.SOLUTIONID \n" +
            " LEFT JOIN TBL_MONITOR_SOLUTION_STAFF  sta on tms.SOLUTIONID = sta.SOLUTIONID\n" +
            " where tms.STAFFID= #{staffid} and tms.TYPE=1 ORDER BY MR.RULEID\n ")
    Integer findTblMonitorRuleByUserCount(BigDecimal staffid);

    @Select("SELECT * FROM TBL_MONITOR_RULE WHERE RULEID = #{ruleid}")
    TblMonitorRule findRuleid(BigDecimal ruleid);

    @SelectProvider(type=TblMonitorRuleSqlConfig.class,method="findAll")
    List<TblMonitorRule> findAll(String solutionid, PageInfo<TblMonitorRule> pageInfo);

    //@Select("select COUNT(*) from TBL_MONITOR_RULE tmr left join TBL_MONITOR_PREWARNING tm on tmr.RULEID = tm.RULEID where tm.SIGNID like '% #{solutionid} %' and tm.resultCount >0  order by tmr.ruleid desc")
    @SelectProvider(type=TblMonitorRuleSqlConfig.class,method="findAllCount")
    Integer findAllCount(String solutionid);
}
